<template>
  <el-table v-loading="loading" :data="inpatientList" @selection-change="handleSelectionChange">
    <el-table-column type="selection" width="55" align="center"/>
    <el-table-column label="床号" align="center" prop="bedNum"/>
    <el-table-column label="状态" align="center" prop="status"/>
    <el-table-column label="姓名" align="center" prop="patientName"/>
    <el-table-column label="性别" align="center" prop="patientSex"/>
    <el-table-column label="年龄" align="center" prop="patientAge"/>
    <el-table-column label="入科时间" align="center" prop="date" width="180">
      <template #default="scope">
        <span>{{ parseTime(scope.row.date, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
      </template>
    </el-table-column>
    <el-table-column label="住院号" align="center" prop="patientId"/>
    <el-table-column label="主要诊断" align="center" prop="diagnose"/>
    <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
      <template #default="scope">
        <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['nurse:chuyuan:edit']">
          修改
        </el-button>
        <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
                   v-hasPermi="['nurse:chuyuan:remove']">删除
        </el-button>
      </template>
    </el-table-column>
  </el-table>

  <el-dialog :title="title" v-model="open" width="500px" append-to-body>
    <el-form ref="chuyuanRef" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="床号" prop="bedNum">
        <el-input v-model="form.bedNum" placeholder="请输入床号"/>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-input v-model="form.status" placeholder="请输入状态"/>
      </el-form-item>
      <el-form-item label="姓名" prop="patientName">
        <el-input v-model="form.patientName" placeholder="请输入姓名"/>
      </el-form-item>
      <el-form-item label="性别" prop="patientSex">
        <el-select v-model="form.patientSex" placeholder="请选择性别">
          <el-option label="男" value="男"/>
          <el-option label="女" value="女"/>
        </el-select>
      </el-form-item>
      <el-form-item label="年龄" prop="patientAge">
        <el-input v-model="form.patientAge" placeholder="请输入年龄"/>
      </el-form-item>
      <el-form-item label="入科时间" prop="date">
        <el-date-picker clearable
                        v-model="form.date"
                        type="datetime"
                        value-format="YYYY-MM-DD HH:mm:ss"
                        placeholder="请选择入科时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="住院号" prop="patientId">
        <el-input v-model="form.patientId" placeholder="请输入住院号"/>
      </el-form-item>
      <el-form-item label="主要诊断" prop="diagnose">
        <el-input
            v-model="form.diagnose"
            placeholder="请输入主要诊断"
            type="textarea"
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
import request from '@/utils/request'
import {parseTime} from "@/utils/ruoyi.js";


const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
let {proxy} = getCurrentInstance()
let inpatientList = ref([])

const data = reactive({
  form: {},
  queryParams: {
    "patientId": 2,
    "patientName": "李虎",
    "patientSex": "男",
    "patientAge": "23",
    "bedNum": 6,
    "department": "无科室",
    "doctor": "张三",
    "diagnose": "无诊断信息",
    "date": "2025-02-04 00:00:00",
    "status": null
  },
  rules: {}
});

const {queryParams, form, rules} = toRefs(data);

function getList() {
  request({
    url: '/jin/inpatient/list',
    method: 'get',
    params: {
      doctorId: localStorage.getItem("userId")
    }
  }).then(res => {
    inpatientList.value = res.rows
    console.log(res.rows)
    loading.value = false
  }).catch(err => {
    console.log(err)
    loading.value = false
  })
}
getList()


</script>
<style scoped>

</style>

